package com.mgq.design.strategy.c1;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <b>功能：</b>工厂类<br>
 * <b>Copyright mgq</b>
 * <li>版本&nbsp;&nbsp;&nbsp;&nbsp;修改日期&nbsp;&nbsp;&nbsp;&nbsp;部　　门&nbsp;&nbsp;&nbsp;&nbsp;作　者&nbsp;&nbsp;&nbsp;&nbsp;变更内容</li><hr>
 * <li>v1.0&nbsp;&nbsp;&nbsp;&nbsp;20220331&nbsp;&nbsp;营业后台&nbsp;&nbsp;&nbsp;&nbsp;马广奇&nbsp;&nbsp;&nbsp;&nbsp;创建类</li>
 * <br><br>
 *
 * @author 马广奇
 * @version 2022-03-31 15:31
 */
@Component
public class CopyStrategyFactory {

    @Resource
    private EmpCopy empCopy;

    @Resource
    private PosCopy PosCopy;

    @Resource
    private PointCopy pointCopy;

    @PostConstruct
    public void setStrategyMap() {
        //key可以考虑使用枚举
        strategyMap.put("EmpCopy",empCopy);
        strategyMap.put("PosCopy",PosCopy);
        strategyMap.put("PointCopy",pointCopy);
    }
    //线程安全.只读
    private static final Map<String, CopyStrategy> strategyMap = new HashMap<>();

    public static CopyStrategy getCopyStrategy(String type) {
        if (strategyMap.get(type) != null) {
            return strategyMap.get(type);
        }
        throw new RuntimeException("类型不存在");
    }
}
